import request from "../../utils/request";
import { TestItemProps } from "../../pages/type";
import { UrlPrefix } from "../../config/const";
// https://ce-staging.home.qinxi1992.cn:12443/
// 获取manage list数据 
export const postToken = (params: any) => {
  return request.post<any, CommonType.ResDataType<any>>(`${UrlPrefix.api}/oauth/token`, null, { params })
}
// 获取用户信息
export const getUsers = () => {
  return request.get<any, CommonType.ResDataType<any>>(`${UrlPrefix.api}/users`)
}
// 获取题库的列表
export const getExams = () => {
  return request.get<any, CommonType.ResDataType<any>>(`${UrlPrefix.api}/exams`)
}
// 获取题库详情
export const getExamsDetailById = (id: string | number) => {
  return request.get<any, CommonType.ResDataType<TestItemProps>>(`${UrlPrefix.api}/exams/${id}`)
}
// 保存答案
export const postAnswer = (id: number | string, data: any) => {
  return request.post<any, CommonType.ResDataType<any>>(`${UrlPrefix.api}/exams/histories/${id}`, data)
}

// 提交结果
export const postResult = (id: number | string, data: any) => {
  return request.post<any, CommonType.ResDataType<any>>(`${UrlPrefix.api}/exams/histories/${id}/submit`, data)
}


// 获取用户答案
export const getExamsAnswer = (id: number | string) => {
  return request.get<any, CommonType.ResDataType<any>>(`${UrlPrefix.api}/exams/histories/${id}/answer`)
}
// 获取用户测评结果
export const getExamsResult = (id: number | string) => {
  return request.get<any, CommonType.ResDataType<any>>(`${UrlPrefix.api}/exams/histories/${id}/result`)
}
// 兑换奖券
export const postRedeem = (data: ProjectType.ExchangeRedeemType) => {
  return request.post<any, CommonType.ResDataType<any>>(`${UrlPrefix.api}/exams/redeem`, data)
}

// 获取答题历史记录
export const getHistories = (req: CommonType.ReqDataType) => {
  return request.get<any, CommonType.ResDataType<any>>(`${UrlPrefix.api}/exams/histories`, { params: req })
}